package com.enjoyor.soa.traffic.rest.efoms.controller;

import com.enjoyor.soa.traffic.api.dto.efoms.DeviceStatusInfoDto;
import com.enjoyor.soa.traffic.frame.annotation.Auth;
import com.enjoyor.soa.traffic.frame.security.bean.dto.UserDto;
import com.enjoyor.soa.traffic.rest.efoms.dubbo.IDevStatusConsumeService;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Auth
@RestController
@RequestMapping({ "/devStatus" })
@Api("DevStatusController")
@CrossOrigin
public class DevStatusController {

    @Autowired
    private IDevStatusConsumeService devStatusConsumeService;

    /**
     * 获取设备状态信息
     * @param devTypeCode
     * @param deviceId
     * @param request
     * @return
     */
	@GetMapping(value = { "/getDevStatusInfo" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiResponse(response=DeviceStatusInfoDto.class, code = 0, message = "")
    @ApiOperation("设备设施状态信息查询")
	@ApiImplicitParams({
    	@ApiImplicitParam(name = "devCategoryCode", value = "设备类别编号", paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "devTypeCode", value = "设备类型编号", paramType = "query", dataType = "String"),
    	@ApiImplicitParam(name = "devId", value = "设备编号", paramType = "query", dataType = "String") })
	public ResultPojo getTemplateInfoList(
			@RequestParam(defaultValue = "",value="devCategoryCode",required=false) String devCategoryCode,
			@RequestParam(defaultValue = "",value="devTypeCode",required=false) String devTypeCode,
			@RequestParam(defaultValue = "",value="devId",required=false) String devId,
			HttpServletRequest request) {
		return devStatusConsumeService.getDevStatusInfo(devCategoryCode, devTypeCode, devId);
	}

    /**
     * 修改设备状态信息
     * @param deviceStatusInfoDto
     * @param request
     * @return
     */
    @PutMapping(value = { "/updateDevStatusInfo" }, consumes = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("修改状态信息")
    public ResultPojo update(@RequestBody DeviceStatusInfoDto deviceStatusInfoDto, HttpServletRequest request) {
        return devStatusConsumeService.updateDevStatusInfo(deviceStatusInfoDto,
                ((UserDto) request.getAttribute("currentUser")).getPersonName());
    }

}
